
// 获取资讯轮播图
function getSlide(){
  $.ajax({
      type:'POST',
      url:address+'/slide/listSlides.do?sence=16&format=true',
      data:{},
      dataType:'json',
      success:function(result){
        if(result.status ==200){
          $("#slide").html(slidesPTL(result.data));
        }
      }
  })
};

//资讯轮播图
function slidesPTL(data){
  var data = data.slideList,html='';
  html +='<ul class="slideBox">';
    $.each(data,function(index,info){
      html +='<li><a href="'+info.clickUrl+'"><div class="cover"></div><img src="'+info.image+'&size=640x300"></a></li>';
    })      
  html +='</ul><div class="point">';
  for(var i=0;i<data.length;i++){
    html += '<span></span>';
  }
  html +='</div>';
  return html;
};
//获取资讯首页列表
function getList(){
  $.ajax({
    type:'POST',
    url:address+'/consultation/list.do?format=true',
    data:{},
    dataType:'json',
    success:function(result){
      if(result.status ==200){
        $("#messageList").html(messageListTPL(result));
      }
    }
  });
};
// 资讯列表模板
function messageListTPL(data){
    var html='';
    $.each(data.data.list,function(index,info){
      html += '<p class="gray m-lr5 p-t5">'+
      '<span class="fr"><span class="m-l10">'+info.dateStr+'</span></span>'+
      '<span class="label">'+info.label+'</span>'+
    '</p>'+
    '<a class="list db p5 b-b" href="messageList-detail.html?id='+info.id+'">'+
        '<dl>'+
          '<dt><img src="'+info.icon+'&size=180x150" class="pic"></dt>'+
          '<dd>'+
            '<div class="name l-h20 black">'+info.name+'</div>'+
            '<p class="gray abstract">'+info.brief+'</p>'+
          '</dd>'+
        '</dl>'+
    '</a>';
    })
  return html;
};

//资讯首页入口
function msgEntrance(){
  $.ajax({
    type:'POST',
    url:address+'/consultation/getClassifyOnPage.do',
    data:{},
    dataType:'json',
    success:function(result){
      if(result.status ==200){
        var html = ""
        $.each(result.data.result,function(index,info){
            html += '<div><a class="news" href="messageList.html?classifyId='+info.id+'" style="background-image:url('+info.image+');background-size:90%"><span>'+info.name+'</span></a></div>'
        })
        $(".message-entrance").html(html);
      }
    }
  });
}


//资讯获取分类列表
function getClassify(classifyId){
  $.ajax({
      type:'POST',
      url:address+'/classify/listByType.do?format=true',
      data:{"type":70},
      dataType:'json',
      success:function(result){
        if(result.status ==200){
          var html = "";
          $.each(result.data.classifyList,function(index,info){
              if(classifyId == info.id){
                html += '<li class="b-yellow orange" data-classifyId="'+info.id+'">'+info.name+'</li>';
              }else{
                html += '<li class="b-yellow" data-classifyId="'+info.id+'">'+info.name+'</li>';
              }
          })
          var $chooseClassify = $("#chooseClassify");
          $chooseClassify.html(html);
          var $li = $chooseClassify.find("li"),
              w = $chooseClassify.closest(".nav").width()-10,
              l = $li.length;
          $li.width(w*0.25);
          $chooseClassify.width(w*0.25*l);
          var myScroll = new IScroll('#classifySlide', {
              scrollbars: false,
              mouseWheel: false,
              momentum:false,
              scrollX:true,
              scrollY:false,
              disableMouse:true,
              shrinkScrollbars: 'clip',
          });
        }
      }
  })
};


//获取资讯列表页列表
function getClassifyList(classifyId){
  $.ajax({
    type:'POST',
    url:address+'/consultation/list.do?format=true',
    data:{"classifyId":classifyId},
    dataType:'json',
    success:function(result){
      if(result.status ==200 && result.data.list !=""){
        $("#messageList-c").html(messageListTPL(result));
      }else{
        var html = '<div class="nodata">此分类没有数据</div>';
        $("#messageList-c").html(html);
      }
    }
  })
};

// 资讯详情
function messageDetail(id){
  $.ajax({
    type:'POST',
    url:address+'/consultation/get.do?',
    data:{"id":id},
    dataType:'json',
    success:function(result){
      if(result.status ==200){
        var info = result.data.consultation,html='';
        html += '<p class="gray m-lr10 p-t5">'+
        '<span class="fr"><span class="m-l10">'+info.dateStr+'</span></span>'+
        '<span class="label">'+info.label+'</span>'+
      '</p>'+
      '<div class="black p10 p-t5 p-b5 b-b">'+info.name+'</div>'+
      '<div class="p10 l-h18">'+info.detail+'</div>';
      $("#messageDetail").html(html);
      }
    }
  });
}
// 资讯分类查询
$("#chooseClassify").on("click","li",function(){
    var $this = $(this),classifyId = $this.attr("data-classifyId");
    $this.addClass("orange").siblings().removeClass("orange");
    getClassifyList(classifyId);
})